<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增套题信息</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-datetimepicker.min.css">
</head>
<body>
<div style="padding: 15px;">
    <form id="fo" class="bs-example bs-example-form" role="form" method='post' enctype="multipart/form-data">
        <div class="input-group">
            <span class="input-group-addon">套题名称</span>
            <input type="text" name='name' class="form-control" placeholder="请输入套题名称">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">藏语套题名称</span>
            <input type="text" name='zname' class="form-control" placeholder="请输入藏语套题名称">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">排序号码</span>
            <input type="text" name='px' class="form-control" placeholder="请输入序列号">
        </div>
        <br>
        <div class="input-group">
            <span class="input-group-addon">套题图标</span>
            <input type="file" name='courseImg' class="form-control"  placeholder="请选择图标文件">
            <input type="hidden" name="exid" value=''>
        </div>
        <br>
        <button type="button" class="btn btn-primary btn-lg btn-block" onclick="ValidForm()">提交保存</button>
    </form>
</div>


</body>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script type="text/javascript">


    function ValidForm() {
        var name=$('input[name=name]').val(),
            px=$('input[name=px]').val(),
            file=$('input[name=courseImg]').val(),
            key=$('input[name=key]').val();
        if(!name){
            layer.msg('请输入套题名称',{icon : 2,time:1000});
            $('input[name=name]').focus();
            return false;
        }
        /*if(!px){
            layer.msg('请输入序列号',{icon : 2,time:1000});
            $('input[name=px]').focus();
            return false;
        }*/
        if(!file){
            layer.msg('请选择图标文件',{icon : 2,time:1000});
            $('input[name=file]').focus();
            return false;
        }

        var formData = new FormData($("#fo")[0]);
        $.ajax({
            async: false,
            cache: false,
            type: "post",
            data: formData,
            url: '/secondType',
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (json) {
                if (json.status == "success") {
                    layer.msg('添加成功', {icon: 1, time: 1000});
                    setTimeout(function () {
                        var index=window.parent.layer.getFrameIndex(window.name);
                        window.parent.layer.close(index);
                    }, 1200);
                }
            },
            error: function () {
                layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
            }
        });
    }
</script>
</html>